package com.songlanyun.modules.account.controller.api;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.account.entity.UserShopRoleEntity;
import com.songlanyun.modules.account.service.UserShopRoleService;
import com.songlanyun.common.utils.R;


/**
 * 会员在每个店铺中的等级（会员的上级会员如查成为商家，自己的绑定店铺成为这个商家的店铺，同时之前所在商家的等级要克隆下来）
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2020-11-05 17:23:13
 */
@RestController
@RequestMapping("api/account/userShopRole")
public class UserShopRoleApiController extends AbstractApiController {
    @Autowired
    private UserShopRoleService userShopRoleService;


    /**
     * 会员在所有店铺的等级设置
     */
    @GetMapping("/getAllByUser")
//    @RequiresPermissions("account:userShopRole:info")
    public R getAllByUser() {
        List<UserShopRoleEntity> list = userShopRoleService.list(
                new LambdaQueryWrapper<UserShopRoleEntity>()
                        .eq(UserShopRoleEntity::getUserId, getUserId(false))
        );

        return R.ok().put("list", list);
    }

    /**
     * 会员在指定店铺的等级设置
     */
    @GetMapping("/getLevelConfig/{shopId}")
//    @RequiresPermissions("account:userShopRole:info")
    public R getLevelConfig(@PathVariable("shopId") Long shopId) {
        UserShopRoleEntity entity = userShopRoleService.getUserShopRole(shopId, getUserId(false));

        return R.ok().put("data", entity);
    }


}
